#pragma once

#include <boost/asio.hpp>
#include <mutex>
#include <map>
#include <memory>


class CSession;

class CServer
{
public:
	CServer(boost::asio::io_context& ioc, unsigned short port);
	~CServer();

	void clearSession(std::string session_id);

private:
	// 接受连接
	void startAccept();
	// 处理连接的回调
	void handleAccept(std::shared_ptr<CSession> new_session, const boost::system::error_code& err);

private:
	unsigned short m_port;
	boost::asio::io_context& m_ioc;
	boost::asio::ip::tcp::acceptor m_acceptor; // 接受连接
	std::map<std::string, std::shared_ptr<CSession>> m_sesssions_map;	// 管理连接
	std::mutex m_mtx;
};

